﻿using IdGen;
using KWT.DRG_DIP.DB;
using KWT.DRG_DIP.DTO.Settlement.Quota;
using KWT.DRG_DIP.ISvc;
using KWT.DRG_DIP.PO.Basic;
using KWT.DRG_DIP.PO.Settlement;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace KWT.DRG_DIP.Svc
{
    public class DIP_QuotaSvc : IQuotaSvc
    {
        public IIdGenerator<long> snow_id { get; set; }
        public DapperHelper dapper { get; set; }
        public EFContext ef { get; set; }
        public (decimal jy, decimal mag, int magType) SetQuota(InSetQuota input)
        {
            decimal jy = 0;
            decimal mag = 0;
            int magType = 0;
            //标杆
            var para = ef.Set<Sys_DIP_Para>().AsNoTracking().SingleOrDefault(x => x.Diag_Code == input.GroupCode);
            if (para != null)
            {
                if (input.InsureType <= 2)
                {
                    //职工医保
                    if (input.InsureType == 1)
                    {
                        //结余
                        jy = para.ZGFFBZ - input.Total;
                        mag = Math.Round(input.Total / para.ZGFFBZ);
                        if (mag <= para.LowMag)
                        {
                            magType = 1;
                        }
                        if (mag >= para.HighMag)
                        {
                            magType = 2;
                        }
                    }
                    else  //居民医保
                    {
                        jy = para.JMFFBZ - input.Total;
                        mag = Math.Round(input.Total / para.JMFFBZ);
                        if (mag <= para.LowMag)
                        {
                            magType = 1;
                        }
                        if (mag >= para.HighMag)
                        {
                            magType = 2;
                        }
                    }
                }
            }
            return (jy, mag, magType);
        }
    }
}
